<?php
include('config.php');
$logu = $_COOKIE['checklog'];
$logsid = $_COOKIE['sid'];
if ($logu && $logsid){
$r = mysql_fetch_array(mysql_query("SELECT `sid` FROM `cookies` WHERE `user` = '$logu' ORDER BY `id` DESC LIMIT 1"));
if($r[sid] == $logsid){$logged = 1;$r2=mysql_fetch_array(mysql_query("SELECT `password` FROM `users` WHERE `username` = '$logu'"));}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>maf1.0</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<script src="js/newf.js"></script>
</head>
<body>
<div>
    <?php if ($logged == 0){?>
	<div>
		<form name="" method="post" action="log.php">    
		<span>Username:</span>
		<span><input name="user" type="text"></span>
		<span>Password:</span>
		<span><input name="pwd" type="password"></span>
		<span id="send"><input type="submit" name="Submit" value="Login"></span>
		</form>
    </div>
    <?php }elseif($logged == 1){ ?>
    <div>
        <span>Welcome back, <b><?php echo $logu;?></b>! <a href="logout.php">logout</a></span>
		<form name="" method="post" action="main.php">   
		<span id="send"><input type="submit" name="Submit2" value="Login"></span>
		</form>
    </div>
    <?php } ?>
</div>

<div id="result"><?php echo urldecode($_GET[log]);?></div>

</html>